package cn.imnaer.common.factory;

import java.math.BigDecimal;

public class DistanceUtil {
    private final static double PI = 3.14159265358979323; // 圆周率
    private final static double R = 6371.229; // 地球的半径

    public static double getDistance(double longt1, double lat1, double longt2, double lat2) {
        double x, y, distance;
        x = (longt2 - longt1) * PI * R
                * Math.cos(((lat1 + lat2) / 2) * PI / 180) / 180;
        y = (lat2 - lat1) * PI * R / 180;
        distance = Math.hypot(x, y);
        if (distance < 20015) {
            BigDecimal bigDecimal = new BigDecimal(distance);
            return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        } else
            return -1.00;
    }


}
